SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.VW_AlumnosenDivisiones
AS
SELECT     dt.CUISE, a.Documento, a.Apellidos + ',' + a.Nombres AS ApellidoyNombre, a.Calle, dt.Mnemo, dt.Curso, dt.Division, dt.idDivision, org.Nombre, 
                      ad.AnioLectivo
FROM         dbo.tb_AlumnoDivision ad INNER JOIN
                      dbo.tb_Divisionestemp dt ON dt.idDivision = ad.Division INNER JOIN
                      dbo.tb_Alumnos a ON a.idAlumno = ad.Alumno INNER JOIN
                      dbo.tb_Organizaciones org ON org.CUISE = dt.CUISE
WHERE     (ad.Division IN
                          (SELECT     iddivision
                            FROM          dbo.tb_divisionestemp dt INNER JOIN
                                                   tb_organizaciones o ON o.cuise = dt.cuise))

GO
GRANT SELECT ON  [dbo].[VW_AlumnosenDivisiones] TO [SoloVer]
GO
